        $(function() {
            var _data = [];
            var _dataTwo = [];
            var _dataThr = [];
            var arrid;
            var _dataLvlThd = []; //直接搜索第三级时的变量
            var selectedValOne = '',
                selectedTxtOne = '',
                selectedValTwo = '',
                selectedTxtTwo = '',
                selectedValThr = '',
                selectedTxtThr = '',
                selectedValFor = '',
                selectedTxtFor = '',
                _current_val = '';
            var _dataPackage;
            $.post('/backend/supply/goods/category', function(dataPackage) {
                _dataPackage = dataPackage;
                var _dataList = _dataPackage['data'];
                //遍历第三级
                for (keyA in _dataList) {
                    if (_dataList[keyA]['list']) {
                        for (keyB in _dataList[keyA]['list']) {
                            if (_dataList[keyA]['list'][keyB]['list']) {
                                for (keyC in _dataList[keyA]['list'][keyB]['list']) {
                                    var json = {
                                        'id': _dataList[keyA]['id'] + ',' + _dataList[keyA]['list'][keyB]['id'] + ',' + _dataList[keyA]['list'][keyB]['list'][keyC]['id'],
                                        'text': _dataList[keyA]['name'] + '>>' + _dataList[keyA]['list'][keyB]['name'] + '>>' + _dataList[keyA]['list'][keyB]['list'][keyC]['name']
                                        // 'text':_dataList[keyA]['list'][keyB]['list'][keyC]['name']
                                    }
                                    _dataLvlThd.push(json);
                                }
                            }
                        }
                    }
                }

                $('#combobox3').combobox({
                    valueField: 'id',
                    textField: 'text',
                    data: _dataLvlThd,
                    onSelect: function(resThr) {
                        var _arr_id = resThr['id'].split(',');
                        $('#combobox1').combobox("setValue", _arr_id[0]);
                        $('#combobox2').combobox("setValue", _arr_id[1]);
                        $('#combobox4').combobox("setValue", _arr_id[2]);
                        $('#current-lvl').val(resThr['id']);
                    }

                })
                //combobox3
                for (var i = 0; i < dataPackage['data'].length; i++) {
                    var _id = dataPackage['data'][i]['id'];
                    var _text = dataPackage['data'][i]['name'];
                    var json = {
                        'id': _id,
                        'text': _text
                    }
                    _data.push(json);
                }
                $('#combobox1').combobox({
                    valueField: 'id',
                    textField: 'text',
                    data: _data,
                    onSelect: function(resOne) {
                        selectedValTwo = '';
                        selectedValFor = '';
                        selectedValOne = resOne['id'];
                        selectedTxtOne = resOne['text'];
                        $('#current-lvl').val(selectedValOne);
                        $(".selected-items").text(selectedTxtOne);
                        var _list2 = '',
                            _list2_id = '',
                            _list3_id = '';
                        _dataTwo = [];
                        _dataThr = [];
                        _dataThr.push({ 'id': '', 'text': '' });
                        $('#combobox4').combobox("loadData", _dataThr);
                        $('#combobox4').combobox("setValue", "请选择");
                        for (var i = 0; i < _dataPackage['data'].length; i++) {
                            if (_dataPackage['data'][i]['id'] == resOne['id']) {
                                if (_dataPackage['data'][i]['list']) {
                                    _list2 = _dataPackage['data'][i]['list'];
                                    _list2_id = i;
                                    for (var j = 0; j < _list2.length; j++) {
                                        var _id2 = _list2[j]['id'];
                                        var _text2 = _list2[j]['name'];
                                        _dataTwo.push({
                                            'id': _id2,
                                            'text': _text2
                                        })
                                    }
                                } else {
                                    _dataTwo.push({ 'id': '', 'text': '' });
                                    _dataThr.push({ 'id': '', 'text': '' });
                                    $('#combobox4').combobox("loadData", _dataThr);
                                    $('#combobox4').combobox("setValue", "请选择");

                                }
                            } //if
                        } //for
                        $('#combobox2').combobox({
                            valueField: 'id',
                            textField: 'text',
                            data: _dataTwo,
                            onSelect: function(resTwo) {
                                selectedValFor = '';
                                selectedValTwo = ',' + resTwo['id'];
                                selectedTxtTwo = ">>" + resTwo['text'];
                                $('#current-lvl').val(selectedValOne + selectedValTwo);
                                $(".selected-items").text(selectedTxtOne + selectedTxtTwo);
                                _dataThr = [];
                                for (var k = 0; k < _list2.length; k++) {
                                    if (_list2[k]['id'] == resTwo['id']) {
                                        if (_list2[k]['list']) {
                                            for (var m = 0; m < _list2[k]['list'].length; m++) {
                                                var _id3 = _list2[k]['list'][m]['id']
                                                var _text3 = _list2[k]['list'][m]['name']
                                                _dataThr.push({ 'id': _id3, 'text': _text3 })
                                            }
                                        } else {
                                            _dataThr.push({ 'id': '', 'text': '' });
                                        } //if
                                    } //if
                                } //for
                                $('#combobox4').combobox({
                                    valueField: 'id',
                                    textField: 'text',
                                    data: _dataThr,
                                    onSelect: function(resFor) {
                                        selectedValFor = ',' + resFor['id'];
                                        selectedTxtFor = ">>" + resFor['text'];
                                        $('#current-lvl').val(selectedValOne + selectedValTwo + selectedValFor);
                                        $(".selected-items").text(selectedTxtOne + selectedTxtTwo + selectedTxtFor);


                                    }
                                })
                            }
                        })
                    }
                });
            }, function() {
                alert("ajax错误！");
            }, "json");
            $("#current_used").change(function () {
                $('#current-lvl').val($(this).find("option:selected").val())
                var txt_tmp=$(this).find("option:selected").text();
                txt_tmp=txt_tmp.split("_").join(">>");
                $(".selected-items").text(txt_tmp);
            })
            $(".btn-submit").click(function() {
                var selectedVal = selectedValOne + selectedValTwo + selectedValFor;
                var self = $(this).closest("form");
                _current_val = $('#current-lvl').val();
                var _data = selectedVal.split(',').length == 3 ? selectedVal : _current_val;
                // if (val.split(',').length < 3 && selectedVal.split(',').length < 3) {
                if (_data.split(',').length < 3) {
                    // shop.message.error('请选择完整类目');
                    $(".selected-items").find(".not-complete").remove();
                    $(".selected-items").append('<em class="not-complete">请选择完整类目！</em>')
                } else {
                     $.ajax({
                         url: self.attr('action'),
                         type: 'post',
                         data: { "data": _data.split(',') },
                         dataType: "json",
                         success: function(d) {
                             if (d["flag"] == 1) {
                                 window.location.href = d["data"]["url"];
                             } else {
                                 alert(d["msg"]);
                             }
                         },
                         error: function() {
                             alert("出错了！")
                         }
                     });
                }
            });
        })
